package com.jzx.service.impl;

import com.jzx.bean.User;
import com.jzx.bean.UserMessage;
import com.jzx.dao.UserDao;
import com.jzx.service.UserMessageService;
import com.jzx.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author JunedQQ
 * @create 2019/6/24
 * @since 1.0.0
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Autowired
    private UserMessageService userMessageService;

    @Override
    public User findUserById(String id) {
        User user =userDao.findUserById(id);
        //获取用户数据
        UserMessage userMessage = userMessageService.getUserMessageByUserId(String.valueOf(user.getId()));
        //设置用户数据
        user.setUserMessage(userMessage);
        return user;
    }

    @Override
    public List<User> findAllUser() {
        List<User> users = userDao.findAllUser();
        //获取用户所对应的用户信息
        for (int i = 0;i<users.size();i++){
            //获取用户id
            String userId = String.valueOf(users.get(i).getId());
            //获取用户信息列表
            UserMessage userMessage = userMessageService.getUserMessageByUserId(userId);
            //存入信息
            users.get(i).setUserMessage(userMessage);
        }
        return users;
    }

    @Override
    public int getUserTotal() {
        return userDao.getUserTotal();
    }

    @Override
    public User findUserByTel(String tel) {
        User user = userDao.findUserByTel(tel);
        //获取用户数据
        UserMessage userMessage = userMessageService.getUserMessageByUserId(String.valueOf(user.getId()));
        //设置用户数据
        user.setUserMessage(userMessage);
        return user;
    }

    @Override
    public String getUserPasswordByTel(String tel) {
        return userDao.getUserPasswordByTel(tel);
    }

    @Override
    public String getUserPasswordById(String id) {
        return userDao.getUserPasswordById(id);
    }

    @Override
    public String getUserPhotoByTel(String tel) {
        return userDao.getUserPhotoByTel(tel);
    }

    @Override
    public String getUserPhotoById(String id) {
        return userDao.getUserPhotoById(id);
    }

    @Override
    public int getUserIdByTel(String tel) {
        return userDao.getUserIdByTel(tel);
    }

    @Override
    public String getUserTelById(int id) {
        return userDao.getUserTelById(id);
    }

    @Override
    public int updateUserPasswordById(int id, String newPassword) {
        return userDao.updateUserPasswordById(id,newPassword);
    }

    @Override
    public int updateUserPasswordByTel(String tel, String newPassword) {
        return userDao.updateUserPasswordByTel(tel,newPassword);
    }

    @Override
    public int updateUserPhotoByTel(String tel, String photo) {
        return userDao.updateUserPhotoByTel(tel,photo);
    }

    @Override
    public int updateUserPhotoById(int id, String photo) {
        return userDao.updateUserPhotoById(id,photo);
    }

    @Override
    public int addUser(User user) {
        return userDao.addUser(user);
    }
}